export const appendStorageInfo = (str, isInit = 2) => {
	const infoKey = 'show_info';
	const info = uni.getStorageSync(infoKey) ?? '';
	if(isInit === 1){
		uni.setStorageSync(infoKey, str);
	}else{
		uni.setStorageSync(infoKey, info + str);
	}
}

export const getAppendStorageInfo = () => {
	const infoKey = 'show_info';
	return uni.getStorageSync(infoKey) ?? '';
}

export const renderDataBaseId = () => {
	const currentTime = Math.floor(new Date().getTime() / 1000);
	let num = currentTime + (Math.floor(Math.random() * 9999) + 1);
	return Number(num);
}

export const requestPermission =  (permissionList) => {
	return new Promise((resolve, reject) => {
		plus.android.requestPermissions(permissionList, function(e){
			if(e.deniedAlways.length>0){	//权限被永久拒绝
			    appendStorageInfo('request permission success1' + JSON.stringify(e))
				// 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
				resolve(e.deniedAlways.length);
			}
			if(e.deniedPresent.length>0){	//权限被临时拒绝
			    appendStorageInfo('request permission success2' + JSON.stringify(e))
				// 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
				resolve(e.deniedPresent.length);
			}
			if(e.granted.length>0){	//权限被允许
			    appendStorageInfo('request permission success3' + JSON.stringify(e))
				//调用依赖获取定位权限的代码
				resolve([])
			}
		}, function(e){
			appendStorageInfo('request permission error' + JSON.stringify(e))
			console.log('Request Permissions error:'+JSON.stringify(e));
		});
	})
}